package view.listeners;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuItem;
import javax.swing.tree.TreePath;

import controller.Controller;

import model.HostAddress;
import model.Subnet;

import view.components.NetworkTree;
import view.dialogs.AddHostDialog;
import view.dialogs.AddIpByListDialog;
import view.dialogs.AddSimpleIpDialog;
import view.dialogs.AddSubnetDialog;
import view.dialogs.HostInfoDialog;
import view.dialogs.InfoDialog;
import view.dialogs.MultiInfoDialog;
import view.dialogs.SubnetInfoDialog;

public class NetworkTreePopUpListener  extends MouseAdapter {

		

		private TreePath item;
		private NetworkTree tree;

		public NetworkTreePopUpListener (TreePath item, NetworkTree tree) {
		this.item = item ;
		this.tree = tree;
		}
		
		@Override
		public void mousePressed(MouseEvent e) {

			JMenuItem item = (JMenuItem) e.getSource();

			if (item.getText().equalsIgnoreCase("Host Löschen")) {
				tree.removeRow();
			
			}
			if (item.getText().equalsIgnoreCase("Subnetz löschen")) {
				tree.removeRow();
			
			}
			
			if (item.getText().equalsIgnoreCase("Subnetz zu Host hinzufügen")) {
				new AddSubnetDialog("neues Subnetz");
			
			} 
			if (item.getText().equalsIgnoreCase("Subnetz Info")) {
				Subnet subnet = tree.getSubnetFromAddress(tree.getSelectedNode().toString());
				Controller.getInstance().setCurrentSubnet(subnet);
				new SubnetInfoDialog("Info");
			
			} 
			if (item.getText().equalsIgnoreCase("Host Info")) {
				HostAddress host = tree.getHostFromAddress(tree.getSelectedNode().toString());
				Controller.getInstance().setCurrentHost(host);
				new HostInfoDialog("Info");
				
			} 
			if (item.getText().equalsIgnoreCase("Neues Host-Netz anlegen")) {
				new AddHostDialog("new Host");

			}
			if (item.getText().equalsIgnoreCase("IP zu Subnetz hinzufügen")) {
				new AddIpByListDialog("dasd");

			}
			
		}
	}


